package com.csu.springbootpetstore.controller;

import com.csu.springbootpetstore.service.UserService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@RestController("/user")
public class UserController {
    @Autowired
    private UserService userService;

    //验证用户
    @PostMapping("/login")
    public String CheckUser(@RequestParam("username") @NotBlank(message = "用户名不能为空") String username,
                            @RequestParam("password") @NotBlank(message = "密码不能为空") String password,
                            Model model){
        String logMsg = userService.isRightOfUser(username, password);
        if (logMsg.equals("success"))
            return "login.html";
        else
            model.addAttribute("logMsg",logMsg);
            return "login.html";
    }
}
